import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { usePermission } from '/@/hooks/web/usePermission';

const { hasPermission } = usePermission();

export const columns: BasicColumn[] = [
  { title: '区域', dataIndex: 'region', width: 40, align: 'left', },
  {
    title: '签单员',
    dataIndex: 'soleName',
    width: 28,
  },
  {
    title: '车商名称',
    dataIndex: 'dealerName',
    width: 80,
    align: 'left',
  },
  {
    title: '客户名字',
    dataIndex: 'customerName',
    width: 30,
  },
  {
    title: '商务政策',
    dataIndex: 'policyType',
    width: 40,
    customRender: ({text}) => render.renderTag(render.renderDict(text, 'policyType'),'green')
  },
  {
    title: '资方产品',
    dataIndex: 'product',
    width: 80,
    align: 'left',
    className: 'text-red-500'
  },
  {
    title: '期数',
    dataIndex: 'timeLimit',
    width: 18,
    customRender: ({text, record}) => {
      if (record.fTimeLimit) {
        return render.renderColor(record.fTimeLimit,'text-red-500')
      } else {
        return record.aTimeLimit
      }
    }
  },
  {
    title: '利率',
    dataIndex: 'rate',
    width: 28,
    align: 'right',
    customRender: ({text, record}) => {
      if (record.fRate) {
        text = record.fRate
        text = text ? (Number(text) * 100).toFixed(2) + "%" : text;
        return render.renderColor(text,'text-red-500')
      } else {
        text = record.aRate
        text = text ? (Number(text) * 100).toFixed(2) + "%" : text;
        return text
      }
    }
  },
  {
    title: 'GPS',
    dataIndex: 'gps',
    width: 28,
    align: 'right',
    customRender: ({text, record}) => {
      if (record.fGps) {
        return render.renderColor(record.fGps,'text-red-500')
      } else {
        return record.aGps
      }
    }
  },
  {
    title: '奖励',
    dataIndex: 'qytotalRewards',
    width: 28,
    className: 'text-red-500',
  },
  {
    title: '附加费',
    dataIndex: 'extraCharge',
    width: 40,
    align: 'right',
    className: 'text-red-500',
  },
  {
    title: '融资总额',
    dataIndex: 'amountTotal',
    width: 40,
    align: 'right',
    className: 'text-blue-600'
  },
  {
    title: '放款日期',
    dataIndex: 'loanDate',
    width: 40,
  },
  {
    title: 'GPS费用',
    dataIndex: 'gpsCost',
    width: 30,
    align: 'right',
    className: 'text-red-500'
  },
  {
    title: '返利系数',
    dataIndex: 'rebateRatio',
    width: 30,
    customRender: ({ text }) => {
      return text ? (Number(text) * 100).toFixed(2) + "%" : text;
    },
    className: 'text-green-500',
    align: 'right',
  },
  {
    title: '车商返利',
    dataIndex: 'dealerRebate',
    width: 35,
    align: 'right',
    className: 'text-green-500'
  },
  {
    title: '备注',
    dataIndex: 'remarks',
    width: 60,
    align: 'left',
  },
  {
    title: '区域营收',
    dataIndex: 'qyIncomeAmount',
    width: 35,
    align: 'right',
    className: 'text-blue-500'
  },
  {
    title: '区域提成',
    dataIndex: 'qyProfitAmount',
    width: 35,
    align: 'right',
    className: 'text-blue-500'
  },
  {
    title: '区域毛利',
    dataIndex: 'zfProfitGross',
    width: 35,
    align: 'right',
    className: 'text-blue-500'
  },
  {
    title: '税金支出',
    dataIndex: 'zfTaxAmount',
    width: 35,
    align: 'right',
    className: 'text-blue-500'
  },
  {
    title: '股东毛利',
    dataIndex: 'nbProfitGross',
    width: 35,
    align: 'right',
    className: 'text-blue-500',
    //auth: 'order:shareholder',
    ifShow: () => {
      return hasPermission('order:shareholder');
    },
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '区域',
    field: 'region',
    component: 'Input'
  },
  {
    label: '业务经理',
    field: 'managerId',
    component: 'Input'
  },
];


